
			
			<script type="text/javascript"
			  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBXjLdTmaYkzOIa-uIHnlWCCEm2MCCiMPg&sensor=true">
			</script>
			
			<script>
			
				var titikPenjualanIconBase = '<?= base_url().'img/misc/'; ?>';
				
				function initialize(){
					var mapProp = {
						center: new google.maps.LatLng(-7.28755, 112.733),
						zoom: 9,
						mapTypeId: google.maps.MapTypeId.ROADMAP
					};
					var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
					allMaps.push(map);
					
					<?php
						if($all_titik_penjualan != null){
							foreach($all_titik_penjualan as $titik){
								echo "var marker".$titik['ID_TITIK_PASOK']." = new google.maps.Marker();";
								echo "marker".$titik['ID_TITIK_PASOK'].".setPosition(new google.maps.LatLng(".$titik['LAT'].", ".$titik['LON']."));";
								echo "marker".$titik['ID_TITIK_PASOK'].".setMap(map);";
								echo "marker".$titik['ID_TITIK_PASOK'].".setIcon(titikPenjualanIconBase + 'titik_penjualan.png');";
								
								echo "var content".$titik['ID_TITIK_PASOK']." = $('#info-window".$titik['ID_TITIK_PASOK']."').html();";
								echo "var infoWindow".$titik['ID_TITIK_PASOK']." = new google.maps.InfoWindow({content: content".$titik['ID_TITIK_PASOK']."});";
								
								echo "onSpotClicked(marker".$titik['ID_TITIK_PASOK'].", content".$titik['ID_TITIK_PASOK'].", infoWindow".$titik['ID_TITIK_PASOK'].", map);";
								
								echo "allMarkers[".$titik['ID_TITIK_PASOK']."] = marker".$titik['ID_TITIK_PASOK'].";";
							}
						}
					
					?>
					
				}
				
				function onSpotClicked(marker, content, infowindow, map){
					google.maps.event.addListener(marker, "mouseover", function () {
						infowindow.setContent(content);
						infowindow.open(map,this);
					});
					
					google.maps.event.addListener(marker, "mouseout", function () {
						infowindow.close();
					});
				}
				
				function deleteTitikPenjualan(idJual, idPasok){
					$.ajax({
						url: "<?= base_url(); ?>titik_penjualan/delete_titik_penjualan",
						type: "POST",
						data: "ID_TITIK_PASOK="+idJual+"&id_titik_pasok="+idPasok,
						success: function(msg){
							//alert(msg);
							window.location = "<?= base_url(); ?>titik_penjualan";
						}
					});
				}
				
				function updateTitikPenjualan(id, submit){
					if(submit == 'false'){
						$('#action-title').html("Edit Titik Penjualan");
						$('#nama').val($('#nama'+id).html());
						$('#alamat').val($('#alamat'+id).html());
						$('#id_kota').val($('#id_kota'+id).val());
						$('#no_telp').val($('#no_telp'+id).html());
						$('#email').val($('#email'+id).html());
						$('#kode_pos').val($('#kode_pos'+id).html());
						$('#tanggal_berdiri').val($('#tanggal_berdiri'+id).html());
						$('#penjualan_normal').val($('#penjualan_normal'+id).html());
						$('#info').val($('#info'+id).html());
						$('#lat').val($('#lat'+id).val());
						$('#lng').val($('#lng'+id).val());
						
						$('#button_panel').html('<button class="btn" onclick="updateTitikPenjualan('+id+', true)">Simpan</button>');
						if(markers[0] == null){
							placeMarker(new google.maps.LatLng($('#lat'+id).val(), $('#lng'+id).val()), allMaps[1]);
						} else {
							markers[0].setPosition(new google.maps.LatLng($('#lat'+id).val(), $('#lng'+id).val()));
							markers[0].setMap(allMaps[1]);
							allMaps[1].setCenter(markers[0].getPosition());
						}
						
						
						
					} else {
						var nama = $('#nama').val();
						var alamat = $('#alamat').val();
						var kota = $('#id_kota').val();
						var noTelp = $('#no_telp').val();
						var email = $('#email').val();
						var kodePos = $('#kode_pos').val();
						var tanggalBerdiri = $('#tanggal_berdiri').val();
						var penjualanNormal = $('#penjualan_normal').val();
						var info = $('#info').val();
						var lat = $('#lat').val();
						var lng = $('#lng').val();
						
						$.ajax({
							url: "<?= base_url(); ?>titik_penjualan/update_titik_penjualan",
							type: "POST",
							data: "id_titik_penjualan="+id+"&nama="+nama+"&alamat="+alamat+"&id_kota="+kota+"&no_telp="+noTelp+"&email="+email+"&kode_pos="+kodePos+"&tanggal_berdiri="+tanggalBerdiri+"&penjualan_normal="+penjualanNormal+"&info="+info+"&lat="+lat+"&lng="+lng,
							success: function(msg){
								//alert(msg);
								window.location = "<?= base_url(); ?>titik_penjualan";
							}
						});
					}
					
				}
				
				function addTitikPenjualan(){
					var nama = $('#nama').val();
					var alamat = $('#alamat').val();
					var kota = $('#id_kota').val();
					var noTelp = $('#no_telp').val();
					var email = $('#email').val();
					var kodePos = $('#kode_pos').val();
					var tanggalBerdiri = $('#tanggal_berdiri').val();
					var penjualanNormal = $('#penjualan_normal').val();
					var info = $('#info').val();
					var lat = $('#lat').val();
					var lng = $('#lng').val();
					
					$.ajax({
						url: "<?= base_url(); ?>titik_penjualan/add_titik_penjualan",
						type: "POST",
						data: "nama="+nama+"&alamat="+alamat+"&id_kota="+kota+"&no_telp="+noTelp+"&email="+email+"&kode_pos="+kodePos+"&tanggal_berdiri="+tanggalBerdiri+"&penjualan_normal="+penjualanNormal+"&info="+info+"&lat="+lat+"&lng="+lng,
						success: function(msg){
							//alert(msg);
							window.location = "<?= base_url(); ?>titik_penjualan";
						}
					});
				}
				
				var allMarkers = [];
				
				function initialize2(){
					var mapProp = {
						center: new google.maps.LatLng(-7.28755, 112.733),
						zoom: 9,
						mapTypeId: google.maps.MapTypeId.ROADMAP
					};
					var map = new google.maps.Map(document.getElementById("googleMap2"),mapProp);
					allMaps.push(map);
					
					google.maps.event.addListener(map, 'click', 
						function(e) {
							if(markers[0] == null){
								placeMarker(e.latLng, map);
							} else {
								markers[0].setPosition(e.latLng);
								markers[0].setMap(map);
							}
							
							$('#lat').val(e.latLng.lat());
							$('#lng').val(e.latLng.lng());
						});
					
				}
				
				function placeMarker(position, map) {
					var marker = new google.maps.Marker({
						position: position,
						map: map
					});
					map.panTo(position);
					marker.setIcon(titikPenjualanIconBase + 'titik_penjualan.png');
					markers.push(marker);
					map.setCenter(marker.getPosition());
				  }
				
				var markers = [];
				var allMaps = [];
				google.maps.event.addDomListener(window, 'load', initialize);
				google.maps.event.addDomListener(window, 'load', initialize2);
				
				
				
			</script>
			
			<div id="titik-jual-edit">
				<?php $this->load->view('titik_penjualan/titik_penjualan_edit', array('NEW' => TRUE)); ?>
			</div></div></div>
			
			<?php foreach($all_titik_penjualan as $titik): ?>
				<div id="info-window<?= $titik['ID_TITIK_PASOK']; ?>" style="width: 330px; height: 300px; overflow-y: auto;" hidden="hidden">
					<table style="width: 300px; height: 130px; overflow-x: auto; overflow-y: auto;">
						<tr>
							<td colspan='2'>
								
							</td>
						</tr>
						<tr>
							<td>Nama</td>
							<td><?= $titik['NAMA']; ?></td>
						</tr>
						<tr>
							<td>Alamat</td>
							<td><?= $titik['ALAMAT']; ?></td>
						</tr>
						<tr>
							<td>Permintaan Normal</td>
							<td><?= $titik['PERMINTAAN_NORMAL']; ?></td>
						</tr>
					</table>
				</div>
			<?php endforeach; ?>
			
			<div id="titik-jual-list">
				<div class="row-fluid sortable">		
					<div class="box span12">
						<div class="box-header well" data-original-title>
							<h2><i class="icon-home"></i> Titik Penjualan</h2>
							<div class="box-icon">
								<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
							</div>
						</div>
						<div class="box-content">
							<table class="table table-striped table-bordered bootstrap-datatable datatable">
							  <thead>
								  <tr>
									  <th>Nama</th>
									  <th>Alamat</th>
									  <th>Kota</th>
									  <th>No Telp</th>
									  <th>Email</th>
									  <th>Kode Pos</th>
									  <th>Tanggal Berdiri</th>
									  <th>Penjualan Normal</th>
									  <th>Info</th>
									  <th>Action</th>
								  </tr>
							  </thead>   
							  <tbody>
								<?php $this->load->view('titik_penjualan/titik_penjualan_list'); ?>
							</tbody>
						  </table>            
						</div>
					</div><!--/span-->
			
				</div><!--/row-->
			</div>